const http = require('http');
const querystring = require('querystring');

// 处理5000端口的所有请求，不管是什么路径
// 测试请求    http://localhost:5000/api/blog/list?author=hamo&keyword=A
const server = http.createServer((req, res) => {
    const method = req.method;
    console.log('method', method);
    const url = req.url;
    console.log('url', url);
    
    // 这里的query属性本来是不存在的，我们给他新增了一个
    req.query = querystring.parse(url.split('?')[1]);
    console.log('query', req.query);

    // res.end('Hello Hamo!');
    res.end(
        JSON.stringify(req.query)
    );
});

server.listen(5000, () => {
    console.log('server running at port 5000');
})